﻿package ui
{
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import global.*;
	
	public class StateMask extends Sprite
	{
		private var msk:Sprite = new Sprite();
		private var tf:TextField;
		private var format:TextFormat;
		
		public var text:String;
		
		public function StateMask()
		{
			initMask();
			
			tf = new TextField();
			msk.addChild(tf);
			addChild(msk);
			
			format = new TextFormat();
			format.size = 25;
			format.color = 0x0000ff;
			format.bold = true;
		}
		
		private function initMask():void
		{
			msk.graphics.beginFill(0x555555, 0.5);
			msk.graphics.drawRect(0,0,GlobalVar.stageWidth, GlobalVar.stageHeight);
			msk.graphics.endFill();
		}
		
		public function set state(tx:String):void
		{
			text = tx;
			update();
		}
		
		private function update():void
		{
			tf.text = text;
			tf.selectable = false;
			tf.autoSize = TextFieldAutoSize.LEFT;
			tf.setTextFormat(format);
			tf.x = (GlobalVar.stageWidth-tf.width)/2;
			tf.y = (GlobalVar.stageHeight-tf.height)/2;
		}
	}
}